<?php
$user = $_SESSION["adminLoggedUserName"];

$section = $_POST["section"];
$block = $db->escapeString(utf8_decode($_POST["block"]));
$language = $db->escapeString(utf8_decode($_POST["language"]));
$visible = $_POST["visible"] == "on" ? 1 : 0;
$html = $db->escapeString(utf8_decode($_POST["html"]));

switch ($_POST["operation"])
{
	// Add
	case "add":
		$operationName = "Inserción";
		$query = "INSERT INTO content (created, created_by, section_id, block, language, visible, html) VALUES (NOW(), '$user', '$section', '$block', '$language', '$visible', '$html')";
		break;
	// Edit
	case "edit":
		$operationName = "Modificación";
		$query = "UPDATE content SET modified = NOW(), modified_by = '$user', block = '$block', language = '$language', visible = '$visible', html = '$html' WHERE id = '".$_POST["id"]."'";
		break;
	// Default
	default:
		echo "ko|No se ha especificado ninguna operación.";
		exit;
}

if (!$db->runQuery($query)) {
	echo "ko|Error de MySQL: ".$db->getErrorDescription();
	exit;
}

echo "ok|".$operationName." correcta.";
exit;
?>
